import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class App {

    private volatile static Map<Integer, List<Integer>> ringData = new ConcurrentHashMap<>();

    public static void main(String[] args) throws IOException {
//        String str = "{\n" +
//                "\t\"1000\": [\"sss\"]\n" +
//                "}";
//        JSONObject jsonObject = JSON.parseObject(str);
//        Set<String> keySet = jsonObject.keySet();
//        for (String s : keySet) {
//            System.out.println(jsonObject.getString(s));
//        }

        // 1000 1010
        // 1111 0101
        // 1111 0110
//        System.out.println(-10 & 15);

//        short a = 10;
//        a += 20;

//        short a = 10;
//        a = a + 20;

        ConcurrentHashMap<String, Object> chm = new ConcurrentHashMap<>();
        chm.put("key", 1000);

        Object val = chm.get("key");

        String uri = "/dgjwhddddddddddadsu1iquw2jdhuebq/activity/info?id=98";
        uri += "10000";

        int hash = spread(uri.hashCode());
        System.out.println(hash);

        String encode = encode(hash, 0);
        System.out.println(encode);
    }

    static final int HASH_BITS = 0x7fffffff;

    static final int spread(int h) {
        return (h ^ (h >>> 16)) & HASH_BITS;
    }


    /**
     * 初始化 62 进制数据，索引位置代表字符的数值，比如 A代表10，z代表61等
     */
    private static String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static int scale = 62;

    /**
     * 将数字转为62进制
     *
     * @param num    Long 型数字
     * @param length 转换后的字符串长度，不足则左侧补0
     * @return 62进制字符串
     */
    public static String encode(long num, int length) {
        StringBuilder sb = new StringBuilder();
        int remainder = 0;

        while (num > scale - 1) {
            /**
             * 对 scale 进行求余，然后将余数追加至 sb 中，由于是从末位开始追加的，因此最后需要反转（reverse）字符串
             */
            remainder = Long.valueOf(num % scale).intValue();
            sb.append(chars.charAt(remainder));

            num = num / scale;
        }

        sb.append(chars.charAt(Long.valueOf(num).intValue()));
        String value = sb.reverse().toString();
        return value;
    }

}
